package com.zha.boss.mvc.models.resp;

import com.zha.boss.enums.resp.RespCode;
import lombok.Data;

/**
 * @Author: zha
 * @CreateTime: 2024年09月05日 18:05
 */
@Data
public class AjaxResult {
    private int code;
    private String msg;
    private Object data;

    //创建表示成功的AjaxResult
    public static AjaxResult ok(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(RespCode.OK.getCode());
        ajaxResult.setMsg(RespCode.OK.getMsg());
        ajaxResult.setData("");
        return ajaxResult;
    }

    public static AjaxResult ok(Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(RespCode.OK.getCode());
        ajaxResult.setMsg(RespCode.OK.getMsg());
        ajaxResult.setData(data);
        return ajaxResult;
    }

    public static AjaxResult warn(RespCode respCode){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(respCode.getCode());
        ajaxResult.setMsg(respCode.getMsg());
        ajaxResult.setData("");
        return ajaxResult;
    }
}
